"""
Copyright (c) 2022 Huawei Technologies Co.,Ltd.

openGauss is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:

          http://license.coscl.org.cn/MulanPSL2

THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
"""
"""
Case Type   : 功能-功能测试
Case Name   : 成功卸载插件
Create At   : 2023/4/23
Owner       : n@ningyali
Description :
    1、打开插件管理页面
    2、点击卸载按钮，确认
Expect      :
    1、【结果1】成功卸载
History     :
"""
import os
import unittest

from openGaussMigrate.common.base import Base
from openGaussMigrate.common.com_log import ComLog
from openGaussMigrate.common.com_node import Macro
from openGaussMigrate.common.com_unit_action import ComUnitAction


class Install0003(unittest.TestCase):
    def setUp(self):
        self.log = ComLog(self.__class__.__name__)
        self.log.info(f'-----{os.path.basename(__file__)} start-----')
        web = Macro('WEB_INFO')
        self.driver = ComUnitAction(web.info['driver_path'], web.info['url'])
        self.driver.open()
        self.driver.login(web.info['user'], web.info['passwd'])
        self.plugin_name = "data-migration"
        self.plugin_name_cn = "数据迁移"
        self.plugin_path = os.path.join(os.getcwd(),
                                        'resources',
                                        'plugins',
                                        'data-migration-5.0.0-repackage.jar')

    @Base.retry(max_n=1)
    @Base.save_img_when_err(cls_name='Install0003')
    def test_case1(self):
        """成功卸载插件"""
        self.log.info('前置操作：安装插件')
        self.driver.install_plugin(self.plugin_name_cn, self.plugin_path)

        self.log.info('卸载插件')
        self.driver.uninstall_plugin(self.plugin_name)

    def tearDown(self):
        self.driver.close()
        self.log.info('teardown run finished')
